{template '_header'}
<div class="page-heading">
	<span class='pull-right'>
		  {ifp 'sale.coupon.add'}
					 <a class='btn btn-primary btn-sm' href="{php echo merchUrl('sale/coupon/add')}"><i class='fa fa-plus'></i> 添加购物优惠券</a>
				       {/if}
		<a class="btn btn-default  btn-sm" href="{php echo merchUrl('sale/coupon')}">返回列表</a>
	</span>
	<h2>{if !empty($item['id'])}编辑{else}添加{/if}购物优惠券 <small>{if !empty($item['id'])}修改【{$item['couponname']}】{/if}</small></h2>
</div>

<form {ife 'sale.coupon' $item}action="" method='post'{/if} class='form-horizontal form-validate'>
    <input type="hidden" name="id" value="{$item['id']}">
 <input type="hidden" name="tab" id='tab' value="{$_GPC['tab']}" />
	<ul class="nav nav-arrow-next nav-tabs" id="myTab">
		<li {if $_GPC['tab']=='basic' || empty($_GPC['tab'])}class="active"{/if} ><a href="#tab_basic">基本</a></li>
		<li {if $_GPC['tab']=='center'}class="active"{/if} ><a href="#tab_center">领取设置</a></li>
		<li {if $_GPC['tab']=='limit'}class="active"{/if} ><a href="#tab_limit">使用限制</a></li>
		<li {if $_GPC['tab']=='resp'}class="active"{/if} ><a href="#tab_resp">推送</a></li>
		<li {if $_GPC['tab']=='usage'}class="active"{/if} ><a href="#tab_usage">使用说明</a></li>
	</ul>

	<div class="tab-content">
		<div class="tab-pane  {if $_GPC['tab']=='basic' || empty($_GPC['tab'])}active{/if}" id="tab_basic">{template 'sale/coupon/post/basic'}</div>
		<div class="tab-pane  {if $_GPC['tab']=='center'}active{/if}" id="tab_center">{template 'sale/coupon/post/center'}</div>
		<div class="tab-pane  {if $_GPC['tab']=='limit'}active{/if}" id="tab_limit">{template 'sale/coupon/post/limit'}</div>
		<div class="tab-pane  {if $_GPC['tab']=='resp'}active{/if}" id="tab_resp" >{template 'sale/coupon/post/resp'}</div>
		<div class="tab-pane  {if $_GPC['tab']=='usage'}active{/if}" id="tab_usage" >{template 'sale/coupon/post/usage'}</div>
	</div>

	<div class="form-group"></div>
	<div class="form-group">
			<label class="col-sm-2 control-label"></label>
			<div class="col-sm-9 col-xs-12">
				 {ife 'sale.coupon' $item}
					<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1"  />

				{/if}
			   <input type="button" name="back" onclick='history.back()' {ife 'sale.coupon' $item}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default" />
			</div>
	</div>
</form>
<script language='javascript'>
      require(['bootstrap'],function(){
             $('#myTab a').click(function (e) {
                 e.preventDefault();
                $('#tab').val( $(this).attr('href'));
                 $(this).tab('show');
             })
     });

    function showbacktype(type){

        $('.backtype').hide();
        $('.backtype' + type).show();
    }
	$(function(){

		$('form').submit(function(){

			if($(':input[name=couponname]').isEmpty()){
				Tip.focus($(':input[name=couponname]'),'请输入优惠券名称!');
				return false;
			}
			var backtype = $(':radio[name=backtype]:checked').val();
			if(backtype=='0'){
				if($(':input[name=deduct]').isEmpty()){
					Tip.focus($(':input[name=deduct]'),'请输入立减多少!');
					return false;
				}
			}else if(backtype=='1'){
				if($(':input[name=discount]').isEmpty()){
					Tip.focus($(':input[name=discount]'),'请输入折扣多少!');
					return false;
				}
			}
			return true;
		})

	})
</script>

{template '_footer'}